Allow preprocessor in example modules - #11486
Conversation
This commit makes ram files work as I/O servers so that code that expects I/O server can use ram files, for example epp:open.
This enables fully in-memory preprocessing using cooked ram files.
Add compile:string/1,2 and compile:noenv_string/2 that compile Erlang
source code from a string or binary. Unlike compile:forms, the source
goes through the Erlang preprocessor (epp), supporting -define, -include,
-ifdef, records, and all other preprocessor directives.
The `{include_path_open, Fun}` option is passed through to epp, enabling
fully in-memory compilation without file system access for include files.
CT Test Results 5 files 530 suites 3h 34m 15s ⏱️ For more details on these failures, see this check. Results for commit 80537f6. ♻️ This comment has been updated with latest results. To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass. See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally. Artifacts
// Erlang/OTP Github Action Bot |
|
@bjorng can you provide related OTP ticket number? Symptom: Lab test otp_SUITE:test_runtime_dependencies_versions fails on master-opu (progress_30) with: Undefined functions in common_test-1.31.1: Root cause: ct_doctest.erl now calls compile:string/2 which only exists in the compiler version introduced by this same branch. The declared minimum runtime dependency (compiler-10.0) doesn't have this function, so xref correctly flags it as undefined against older compiler versions. Fix: Bump the compiler version in lib/common_test/src/common_test.app.src runtime_dependencies to the compiler version that includes compile:string/2 (i.e. the version this branch produces). |
This PR adds support for the preprocessor when parsing example module code using ct_doctest. It does this by adding some other new features:
cooked, that is they return apid()instead of a raw handle. This makes it possible to use functions in theiomodule that epp needs.epp:parse_fileso that we can pass the cooked ram file.compile:string/1,2that instructs the compiler to compile an Erlang module from the provided string.Then I've put all this together so that ct_doctest uses
compile:string()to compile module examples so that tuple records, macros and other epp features work.I think the
compiler:string/1,2function could be useful for a variety of things as it makes it much easier to turn generated code strings into runnable code.While doing this I also added doctests for
eppandcompile.I've added special "since" commits that should be updated with the correct ticket number if/when we merge this.